package org.example;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author zhl
 * @version 1.0
 * @ClassName
 * @date 2020/10/31 16:45
 */
public class FileRead {
    public static void main(String[] args) {
        try {
            System.setProperty("HADOOP_USER_NAME", "hadoop");
            String HDFSUri = "hdfs://192.168.136.132:9000";
            Configuration conf = new Configuration();
            conf.set("fs.defaultFS", HDFSUri);
            conf.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");
            FileSystem fs = FileSystem.get(conf);
            Path file = new Path("input/file2.txt");
            FSDataInputStream getIt = fs.open(file);
            BufferedReader d = new BufferedReader(new InputStreamReader(getIt));
            String content = d.readLine();
            System.out.println(content);
            d.close();
            fs.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
